package cn.izeno.wx

import cn.izeno.wx.models.component.*
import cn.izeno.wx.service.WX
import org.junit.Before
import org.junit.Test
import org.slf4j.LoggerFactory

class WeappOpenTest {
  val logger = LoggerFactory.getLogger(this::class.java.name)
  var err: Throwable? = null

  var appid: String = ""
  var appToken: String = ""

  @Before
  fun setup() {
    ComponentApp.accessToken = "22_ygZJ39_UEQGv70cyh1ND6XW76_vV6Y163j1skQ3Asz-u-OMa0j03dOF4tuyZtX7LRk62I74Iv1VWZimy5rkGRLjM59CTRurHwbgIrdvnIon1drp4wJTxFVJkcQMQX2pCNykA2xSDuaG8Qyr9SPTfAEAKHL"
    appid = "wxaa0eec49475120ee"
    appToken = "22_FJ8lB_9Dbb8o6WPk3Wa_7H_QF89qSqhqTcW6zq1ub6-mUJWr8GVWWTf-DL_HGZnmQDARnQIIwzp-OnYo1hVBjudgpBSxvVDjsDBHWy6Y_wVAFu7-Bu6LARRucpKQluwhbjb4X4jGarg01JvJPZTaAJDISM"
  }

  @Test
  fun testGetOpen() {
    WX.open.openGet(Appid(appid), appToken)
        .doOnError { err = it }
        .subscribe { logger.info(it.prettyJson()) }

    assert(err == null)
  }

  @Test
  fun testBindOpen() {
    WX.open.openBind(OpenBind(appid, "gh_e50f915e35e5"), appToken)
        .doOnError { err = it }
        .subscribe { logger.info(it.prettyJson()) }

    assert(err == null)
  }

  @Test
  fun testWeappCategory() {
    WX.open.weappCategoryFC(APP_TOKEN)
        .doOnError { err = it }
        .subscribe { logger.info(it.prettyJson()) }

    assert(err == null)
  }

  @Test
  fun testWeappInfo(){
    WX.open.weappInfo(APP_TOKEN)
        .doOnError { err = it }
        .subscribe { logger.info(it.prettyJson()) }

    assert(err == null)
  }

  @Test
  fun a() {
    ComponentApp.accessToken = "A"
    WX.open.weappFastRegister(FastCreateWeappInfo(), ComponentApp.accessToken).subscribe()
    ComponentApp.accessToken = "B"
    WX.open.weappFastRegister(FastCreateWeappInfo(), ComponentApp.accessToken).subscribe()
  }

}